home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / info / lispref.info-5 < prev    next >
Encoding:
GNU Info File  |  1995-09-01  |  44.8 KB  |  1,206 lines

  1. This is Info file ../../info/lispref.info, produced by Makeinfo-1.63
  2. from the input file lispref.texi.
  3.  
  4.    Edition History:
  5.  
  6.    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
  7. Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
  8. Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
  9. XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
  10. GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
  11. Programmer's Manual (for 19.13) Third Edition, July 1995
  12.  
  13.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
  14. Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
  15. Copyright (C) 1995 Amdahl Corporation.  Copyright (C) 1995 Ben Wing.
  16.  
  17.    Permission is granted to make and distribute verbatim copies of this
  18. manual provided the copyright notice and this permission notice are
  19. preserved on all copies.
  20.  
  21.    Permission is granted to copy and distribute modified versions of
  22. this manual under the conditions for verbatim copying, provided that the
  23. entire resulting derived work is distributed under the terms of a
  24. permission notice identical to this one.
  25.  
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that this permission notice may be stated in a
  29. translation approved by the Foundation.
  30.  
  31.    Permission is granted to copy and distribute modified versions of
  32. this manual under the conditions for verbatim copying, provided also
  33. that the section entitled "GNU General Public License" is included
  34. exactly as in the original, and provided that the entire resulting
  35. derived work is distributed under the terms of a permission notice
  36. identical to this one.
  37.  
  38.    Permission is granted to copy and distribute translations of this
  39. manual into another language, under the above conditions for modified
  40. versions, except that the section entitled "GNU General Public License"
  41. may be included in a translation approved by the Free Software
  42. Foundation instead of in the original English.
  43.  
  44. 
  45. File: lispref.info,  Node: Formatting Strings,  Next: Character Case,  Prev: String Conversion,  Up: Strings and Characters
  46.  
  47. Formatting Strings
  48. ==================
  49.  
  50.    "Formatting" means constructing a string by substitution of computed
  51. values at various places in a constant string.  This string controls
  52. how the other values are printed as well as where they appear; it is
  53. called a "format string".
  54.  
  55.    Formatting is often useful for computing messages to be displayed.
  56. In fact, the functions `message' and `error' provide the same
  57. formatting feature described here; they differ from `format' only in
  58. how they use the result of formatting.
  59.  
  60.  - Function: format STRING &rest OBJECTS
  61.      This function returns a new string that is made by copying STRING
  62.      and then replacing any format specification in the copy with
  63.      encodings of the corresponding OBJECTS.  The arguments OBJECTS are
  64.      the computed values to be formatted.
  65.  
  66.    A format specification is a sequence of characters beginning with a
  67. `%'.  Thus, if there is a `%d' in STRING, the `format' function
  68. replaces it with the printed representation of one of the values to be
  69. formatted (one of the arguments OBJECTS).  For example:
  70.  
  71.      (format "The value of fill-column is %d." fill-column)
  72.           => "The value of fill-column is 72."
  73.  
  74.    If STRING contains more than one format specification, the format
  75. specifications correspond with successive values from OBJECTS.  Thus,
  76. the first format specification in STRING uses the first such value, the
  77. second format specification uses the second such value, and so on.  Any
  78. extra format specifications (those for which there are no corresponding
  79. values) cause unpredictable behavior.  Any extra values to be formatted
  80. are ignored.
  81.  
  82.    Certain format specifications require values of particular types.
  83. However, no error is signaled if the value actually supplied fails to
  84. have the expected type.  Instead, the output is likely to be
  85. meaningless.
  86.  
  87.    Here is a table of valid format specifications:
  88.  
  89. `%s'
  90.      Replace the specification with the printed representation of the
  91.      object, made without quoting.  Thus, strings are represented by
  92.      their contents alone, with no `"' characters, and symbols appear
  93.      without `\' characters.
  94.  
  95.      If there is no corresponding object, the empty string is used.
  96.  
  97. `%S'
  98.      Replace the specification with the printed representation of the
  99.      object, made with quoting.  Thus, strings are enclosed in `"'
  100.      characters, and `\' characters appear where necessary before
  101.      special characters.
  102.  
  103.      If there is no corresponding object, the empty string is used.
  104.  
  105. `%o'
  106.      Replace the specification with the base-eight representation of an
  107.      integer.
  108.  
  109. `%d'
  110.      Replace the specification with the base-ten representation of an
  111.      integer.
  112.  
  113. `%x'
  114.      Replace the specification with the base-sixteen representation of
  115.      an integer.
  116.  
  117. `%c'
  118.      Replace the specification with the character which is the value
  119.      given.
  120.  
  121. `%e'
  122.      Replace the specification with the exponential notation for a
  123.      floating point number.
  124.  
  125. `%f'
  126.      Replace the specification with the decimal-point notation for a
  127.      floating point number.
  128.  
  129. `%g'
  130.      Replace the specification with notation for a floating point
  131.      number, using either exponential notation or decimal-point
  132.      notation whichever is shorter.
  133.  
  134. `%%'
  135.      A single `%' is placed in the string.  This format specification is
  136.      unusual in that it does not use a value.  For example, `(format "%%
  137.      %d" 30)' returns `"% 30"'.
  138.  
  139.    Any other format character results in an `Invalid format operation'
  140. error.
  141.  
  142.    Here are several examples:
  143.  
  144.      (format "The name of this buffer is %s." (buffer-name))
  145.           => "The name of this buffer is strings.texi."
  146.      
  147.      (format "The buffer object prints as %s." (current-buffer))
  148.           => "The buffer object prints as #<buffer strings.texi>."
  149.      
  150.      (format "The octal value of %d is %o,
  151.               and the hex value is %x." 18 18 18)
  152.           => "The octal value of 18 is 22,
  153.               and the hex value is 12."
  154.  
  155.    All the specification characters allow an optional numeric prefix
  156. between the `%' and the character.  The optional numeric prefix defines
  157. the minimum width for the object.  If the printed representation of the
  158. object contains fewer characters than this, then it is padded.  The
  159. padding is on the left if the prefix is positive (or starts with zero)
  160. and on the right if the prefix is negative.  The padding character is
  161. normally a space, but if the numeric prefix starts with a zero, zeros
  162. are used for padding.
  163.  
  164.      (format "%06d is padded on the left with zeros" 123)
  165.           => "000123 is padded on the left with zeros"
  166.      
  167.      (format "%-6d is padded on the right" 123)
  168.           => "123    is padded on the right"
  169.  
  170.    `format' never truncates an object's printed representation, no
  171. matter what width you specify.  Thus, you can use a numeric prefix to
  172. specify a minimum spacing between columns with no risk of losing
  173. information.
  174.  
  175.    In the following three examples, `%7s' specifies a minimum width of
  176. 7.  In the first case, the string inserted in place of `%7s' has only 3
  177. letters, so 4 blank spaces are inserted for padding.  In the second
  178. case, the string `"specification"' is 13 letters wide but is not
  179. truncated.  In the third case, the padding is on the right.
  180.  
  181.      (format "The word `%7s' actually has %d letters in it."
  182.              "foo" (length "foo"))
  183.           => "The word `    foo' actually has 3 letters in it."
  184.  
  185.      (format "The word `%7s' actually has %d letters in it."
  186.              "specification" (length "specification"))
  187.           => "The word `specification' actually has 13 letters in it."
  188.  
  189.      (format "The word `%-7s' actually has %d letters in it."
  190.              "foo" (length "foo"))
  191.           => "The word `foo    ' actually has 3 letters in it."
  192.  
  193. 
  194. File: lispref.info,  Node: Character Case,  Next: Case Table,  Prev: Formatting Strings,  Up: Strings and Characters
  195.  
  196. Character Case
  197. ==============
  198.  
  199.    The character case functions change the case of single characters or
  200. of the contents of strings.  The functions convert only alphabetic
  201. characters (the letters `A' through `Z' and `a' through `z'); other
  202. characters are not altered.  The functions do not modify the strings
  203. that are passed to them as arguments.
  204.  
  205.    The examples below use the characters `X' and `x' which have ASCII
  206. codes 88 and 120 respectively.
  207.  
  208.  - Function: downcase STRING-OR-CHAR
  209.      This function converts a character or a string to lower case.
  210.  
  211.      When the argument to `downcase' is a string, the function creates
  212.      and returns a new string in which each letter in the argument that
  213.      is upper case is converted to lower case.  When the argument to
  214.      `downcase' is a character, `downcase' returns the corresponding
  215.      lower case character.  This value is an integer.  If the original
  216.      character is lower case, or is not a letter, then the value equals
  217.      the original character.
  218.  
  219.           (downcase "The cat in the hat")
  220.                => "the cat in the hat"
  221.           
  222.           (downcase ?X)
  223.                => 120
  224.  
  225.  - Function: upcase STRING-OR-CHAR
  226.      This function converts a character or a string to upper case.
  227.  
  228.      When the argument to `upcase' is a string, the function creates
  229.      and returns a new string in which each letter in the argument that
  230.      is lower case is converted to upper case.
  231.  
  232.      When the argument to `upcase' is a character, `upcase' returns the
  233.      corresponding upper case character.  This value is an integer.  If
  234.      the original character is upper case, or is not a letter, then the
  235.      value equals the original character.
  236.  
  237.           (upcase "The cat in the hat")
  238.                => "THE CAT IN THE HAT"
  239.           
  240.           (upcase ?x)
  241.                => 88
  242.  
  243.  - Function: capitalize STRING-OR-CHAR
  244.      This function capitalizes strings or characters.  If
  245.      STRING-OR-CHAR is a string, the function creates and returns a new
  246.      string, whose contents are a copy of STRING-OR-CHAR in which each
  247.      word has been capitalized.  This means that the first character of
  248.      each word is converted to upper case, and the rest are converted
  249.      to lower case.
  250.  
  251.      The definition of a word is any sequence of consecutive characters
  252.      that are assigned to the word constituent syntax class in the
  253.      current syntax table (*Note Syntax Class Table::).
  254.  
  255.      When the argument to `capitalize' is a character, `capitalize' has
  256.      the same result as `upcase'.
  257.  
  258.           (capitalize "The cat in the hat")
  259.                => "The Cat In The Hat"
  260.           
  261.           (capitalize "THE 77TH-HATTED CAT")
  262.                => "The 77th-Hatted Cat"
  263.           
  264.           (capitalize ?x)
  265.                => 88
  266.  
  267. 
  268. File: lispref.info,  Node: Case Table,  Prev: Character Case,  Up: Strings and Characters
  269.  
  270. The Case Table
  271. ==============
  272.  
  273.    You can customize case conversion by installing a special "case
  274. table".  A case table specifies the mapping between upper case and lower
  275. case letters.  It affects both the string and character case conversion
  276. functions (see the previous section) and those that apply to text in the
  277. buffer (*note Case Changes::.).  You need a case table if you are using
  278. a language which has letters other than the standard ASCII letters.
  279.  
  280.    A case table is a list of this form:
  281.  
  282.      (DOWNCASE UPCASE CANONICALIZE EQUIVALENCES)
  283.  
  284. where each element is either `nil' or a string of length 256.  The
  285. element DOWNCASE says how to map each character to its lower-case
  286. equivalent.  The element UPCASE maps each character to its upper-case
  287. equivalent.  If lower and upper case characters are in one-to-one
  288. correspondence, use `nil' for UPCASE; then XEmacs deduces the upcase
  289. table from DOWNCASE.
  290.  
  291.    For some languages, upper and lower case letters are not in
  292. one-to-one correspondence.  There may be two different lower case
  293. letters with the same upper case equivalent.  In these cases, you need
  294. to specify the maps for both directions.
  295.  
  296.    The element CANONICALIZE maps each character to a canonical
  297. equivalent; any two characters that are related by case-conversion have
  298. the same canonical equivalent character.
  299.  
  300.    The element EQUIVALENCES is a map that cyclicly permutes each
  301. equivalence class (of characters with the same canonical equivalent).
  302. (For ordinary ASCII, this would map `a' into `A' and `A' into `a', and
  303. likewise for each set of equivalent characters.)
  304.  
  305.    When you construct a case table, you can provide `nil' for
  306. CANONICALIZE; then Emacs fills in this string from UPCASE and DOWNCASE.
  307. You can also provide `nil' for EQUIVALENCES; then Emacs fills in this
  308. string from CANONICALIZE.  In a case table that is actually in use,
  309. those components are non-`nil'.  Do not try to specify EQUIVALENCES
  310. without also specifying CANONICALIZE.
  311.  
  312.    Each buffer has a case table.  XEmacs also has a "standard case
  313. table" which is copied into each buffer when you create the buffer.
  314. Changing the standard case table doesn't affect any existing buffers.
  315.  
  316.    Here are the functions for working with case tables:
  317.  
  318.  - Function: case-table-p OBJECT
  319.      This predicate returns non-`nil' if OBJECT is a valid case table.
  320.  
  321.  - Function: set-standard-case-table TABLE
  322.      This function makes TABLE the standard case table, so that it will
  323.      apply to any buffers created subsequently.
  324.  
  325.  - Function: standard-case-table
  326.      This returns the standard case table.
  327.  
  328.  - Function: current-case-table
  329.      This function returns the current buffer's case table.
  330.  
  331.  - Function: set-case-table TABLE
  332.      This sets the current buffer's case table to TABLE.
  333.  
  334.    The following three functions are convenient subroutines for packages
  335. that define non-ASCII character sets.  They modify a string
  336. DOWNCASE-TABLE provided as an argument; this should be a string to be
  337. used as the DOWNCASE part of a case table.  They also modify the
  338. standard syntax table.  *Note Syntax Tables::.
  339.  
  340.  - Function: set-case-syntax-pair UC LC DOWNCASE-TABLE
  341.      This function specifies a pair of corresponding letters, one upper
  342.      case and one lower case.
  343.  
  344.  - Function: set-case-syntax-delims L R DOWNCASE-TABLE
  345.      This function makes characters L and R a matching pair of
  346.      case-invariant delimiters.
  347.  
  348.  - Function: set-case-syntax CHAR SYNTAX DOWNCASE-TABLE
  349.      This function makes CHAR case-invariant, with syntax SYNTAX.
  350.  
  351.  - Command: describe-buffer-case-table
  352.      This command displays a description of the contents of the current
  353.      buffer's case table.
  354.  
  355.    You can load the library `iso-syntax' to set up the standard syntax
  356. table and define a case table for the 8-bit ISO Latin 1 character set.
  357.  
  358. 
  359. File: lispref.info,  Node: Lists,  Next: Sequences Arrays Vectors,  Prev: Strings and Characters,  Up: Top
  360.  
  361. Lists
  362. *****
  363.  
  364.    A "list" represents a sequence of zero or more elements (which may
  365. be any Lisp objects).  The important difference between lists and
  366. vectors is that two or more lists can share part of their structure; in
  367. addition, you can insert or delete elements in a list without copying
  368. the whole list.
  369.  
  370. * Menu:
  371.  
  372. * Cons Cells::          How lists are made out of cons cells.
  373. * Lists as Boxes::                 Graphical notation to explain lists.
  374. * List-related Predicates::        Is this object a list?  Comparing two lists.
  375. * List Elements::       Extracting the pieces of a list.
  376. * Building Lists::      Creating list structure.
  377. * Modifying Lists::     Storing new pieces into an existing list.
  378. * Sets And Lists::      A list can represent a finite mathematical set.
  379. * Association Lists::   A list can represent a finite relation or mapping.
  380.  
  381. 
  382. File: lispref.info,  Node: Cons Cells,  Next: Lists as Boxes,  Up: Lists
  383.  
  384. Lists and Cons Cells
  385. ====================
  386.  
  387.    Lists in Lisp are not a primitive data type; they are built up from
  388. "cons cells".  A cons cell is a data object that represents an ordered
  389. pair.  It records two Lisp objects, one labeled as the CAR, and the
  390. other labeled as the CDR.  These names are traditional; see *Note Cons
  391. Cell Type::.  CDR is pronounced "could-er."
  392.  
  393.    A list is a series of cons cells chained together, one cons cell per
  394. element of the list.  By convention, the CARs of the cons cells are the
  395. elements of the list, and the CDRs are used to chain the list: the CDR
  396. of each cons cell is the following cons cell.  The CDR of the last cons
  397. cell is `nil'.  This asymmetry between the CAR and the CDR is entirely
  398. a matter of convention; at the level of cons cells, the CAR and CDR
  399. slots have the same characteristics.
  400.  
  401.    Because most cons cells are used as part of lists, the phrase "list
  402. structure" has come to mean any structure made out of cons cells.
  403.  
  404.    The symbol `nil' is considered a list as well as a symbol; it is the
  405. list with no elements.  For convenience, the symbol `nil' is considered
  406. to have `nil' as its CDR (and also as its CAR).
  407.  
  408.    The CDR of any nonempty list L is a list containing all the elements
  409. of L except the first.
  410.  
  411. 
  412. File: lispref.info,  Node: Lists as Boxes,  Next: List-related Predicates,  Prev: Cons Cells,  Up: Lists
  413.  
  414. Lists as Linked Pairs of Boxes
  415. ==============================
  416.  
  417.    A cons cell can be illustrated as a pair of boxes.  The first box
  418. represents the CAR and the second box represents the CDR.  Here is an
  419. illustration of the two-element list, `(tulip lily)', made from two
  420. cons cells:
  421.  
  422.       ---------------         ---------------
  423.      | car   | cdr   |       | car   | cdr   |
  424.      | tulip |   o---------->| lily  |  nil  |
  425.      |       |       |       |       |       |
  426.       ---------------         ---------------
  427.  
  428.    Each pair of boxes represents a cons cell.  Each box "refers to",
  429. "points to" or "contains" a Lisp object.  (These terms are synonymous.)
  430. The first box, which is the CAR of the first cons cell, contains the
  431. symbol `tulip'.  The arrow from the CDR of the first cons cell to the
  432. second cons cell indicates that the CDR of the first cons cell points
  433. to the second cons cell.
  434.  
  435.    The same list can be illustrated in a different sort of box notation
  436. like this:
  437.  
  438.          ___ ___      ___ ___
  439.         |___|___|--> |___|___|--> nil
  440.           |            |
  441.           |            |
  442.            --> tulip    --> lily
  443.  
  444.    Here is a more complex illustration, showing the three-element list,
  445. `((pine needles) oak maple)', the first element of which is a
  446. two-element list:
  447.  
  448.          ___ ___      ___ ___      ___ ___
  449.         |___|___|--> |___|___|--> |___|___|--> nil
  450.           |            |            |
  451.           |            |            |
  452.           |             --> oak      --> maple
  453.           |
  454.           |     ___ ___      ___ ___
  455.            --> |___|___|--> |___|___|--> nil
  456.                  |            |
  457.                  |            |
  458.                   --> pine     --> needles
  459.  
  460.    The same list represented in the first box notation looks like this:
  461.  
  462.       --------------       --------------       --------------
  463.      | car   | cdr  |     | car   | cdr  |     | car   | cdr  |
  464.      |   o   |   o------->| oak   |   o------->| maple |  nil |
  465.      |   |   |      |     |       |      |     |       |      |
  466.       -- | ---------       --------------       --------------
  467.          |
  468.          |
  469.          |        --------------       ----------------
  470.          |       | car   | cdr  |     | car     | cdr  |
  471.           ------>| pine  |   o------->| needles |  nil |
  472.                  |       |      |     |         |      |
  473.                   --------------       ----------------
  474.  
  475.    *Note Cons Cell Type::, for the read and print syntax of cons cells
  476. and lists, and for more "box and arrow" illustrations of lists.
  477.  
  478. 
  479. File: lispref.info,  Node: List-related Predicates,  Next: List Elements,  Prev: Lists as Boxes,  Up: Lists
  480.  
  481. Predicates on Lists
  482. ===================
  483.  
  484.    The following predicates test whether a Lisp object is an atom, is a
  485. cons cell or is a list, or whether it is the distinguished object
  486. `nil'.  (Many of these predicates can be defined in terms of the
  487. others, but they are used so often that it is worth having all of them.)
  488.  
  489.  - Function: consp OBJECT
  490.      This function returns `t' if OBJECT is a cons cell, `nil'
  491.      otherwise.  `nil' is not a cons cell, although it *is* a list.
  492.  
  493.  - Function: atom OBJECT
  494.      This function returns `t' if OBJECT is an atom, `nil' otherwise.
  495.      All objects except cons cells are atoms.  The symbol `nil' is an
  496.      atom and is also a list; it is the only Lisp object that is both.
  497.  
  498.           (atom OBJECT) == (not (consp OBJECT))
  499.  
  500.  - Function: listp OBJECT
  501.      This function returns `t' if OBJECT is a cons cell or `nil'.
  502.      Otherwise, it returns `nil'.
  503.  
  504.           (listp '(1))
  505.                => t
  506.           (listp '())
  507.                => t
  508.  
  509.  - Function: nlistp OBJECT
  510.      This function is the opposite of `listp': it returns `t' if OBJECT
  511.      is not a list.  Otherwise, it returns `nil'.
  512.  
  513.           (listp OBJECT) == (not (nlistp OBJECT))
  514.  
  515.  - Function: null OBJECT
  516.      This function returns `t' if OBJECT is `nil', and returns `nil'
  517.      otherwise.  This function is identical to `not', but as a matter
  518.      of clarity we use `null' when OBJECT is considered a list and
  519.      `not' when it is considered a truth value (see `not' in *Note
  520.      Combining Conditions::).
  521.  
  522.           (null '(1))
  523.                => nil
  524.           (null '())
  525.                => t
  526.  
  527. 
  528. File: lispref.info,  Node: List Elements,  Next: Building Lists,  Prev: List-related Predicates,  Up: Lists
  529.  
  530. Accessing Elements of Lists
  531. ===========================
  532.  
  533.  - Function: car CONS-CELL
  534.      This function returns the value pointed to by the first pointer of
  535.      the cons cell CONS-CELL.  Expressed another way, this function
  536.      returns the CAR of CONS-CELL.
  537.  
  538.      As a special case, if CONS-CELL is `nil', then `car' is defined to
  539.      return `nil'; therefore, any list is a valid argument for `car'.
  540.      An error is signaled if the argument is not a cons cell or `nil'.
  541.  
  542.           (car '(a b c))
  543.                => a
  544.           (car '())
  545.                => nil
  546.  
  547.  - Function: cdr CONS-CELL
  548.      This function returns the value pointed to by the second pointer of
  549.      the cons cell CONS-CELL.  Expressed another way, this function
  550.      returns the CDR of CONS-CELL.
  551.  
  552.      As a special case, if CONS-CELL is `nil', then `cdr' is defined to
  553.      return `nil'; therefore, any list is a valid argument for `cdr'.
  554.      An error is signaled if the argument is not a cons cell or `nil'.
  555.  
  556.           (cdr '(a b c))
  557.                => (b c)
  558.           (cdr '())
  559.                => nil
  560.  
  561.  - Function: car-safe OBJECT
  562.      This function lets you take the CAR of a cons cell while avoiding
  563.      errors for other data types.  It returns the CAR of OBJECT if
  564.      OBJECT is a cons cell, `nil' otherwise.  This is in contrast to
  565.      `car', which signals an error if OBJECT is not a list.
  566.  
  567.           (car-safe OBJECT)
  568.           ==
  569.           (let ((x OBJECT))
  570.             (if (consp x)
  571.                 (car x)
  572.               nil))
  573.  
  574.  - Function: cdr-safe OBJECT
  575.      This function lets you take the CDR of a cons cell while avoiding
  576.      errors for other data types.  It returns the CDR of OBJECT if
  577.      OBJECT is a cons cell, `nil' otherwise.  This is in contrast to
  578.      `cdr', which signals an error if OBJECT is not a list.
  579.  
  580.           (cdr-safe OBJECT)
  581.           ==
  582.           (let ((x OBJECT))
  583.             (if (consp x)
  584.                 (cdr x)
  585.               nil))
  586.  
  587.  - Function: nth N LIST
  588.      This function returns the Nth element of LIST.  Elements are
  589.      numbered starting with zero, so the CAR of LIST is element number
  590.      zero.  If the length of LIST is N or less, the value is `nil'.
  591.  
  592.      If N is negative, `nth' returns the first element of LIST.
  593.  
  594.           (nth 2 '(1 2 3 4))
  595.                => 3
  596.           (nth 10 '(1 2 3 4))
  597.                => nil
  598.           (nth -3 '(1 2 3 4))
  599.                => 1
  600.           
  601.           (nth n x) == (car (nthcdr n x))
  602.  
  603.  - Function: nthcdr N LIST
  604.      This function returns the Nth CDR of LIST.  In other words, it
  605.      removes the first N links of LIST and returns what follows.
  606.  
  607.      If N is zero or negative, `nthcdr' returns all of LIST.  If the
  608.      length of LIST is N or less, `nthcdr' returns `nil'.
  609.  
  610.           (nthcdr 1 '(1 2 3 4))
  611.                => (2 3 4)
  612.           (nthcdr 10 '(1 2 3 4))
  613.                => nil
  614.           (nthcdr -3 '(1 2 3 4))
  615.                => (1 2 3 4)
  616.  
  617. 
  618. File: lispref.info,  Node: Building Lists,  Next: Modifying Lists,  Prev: List Elements,  Up: Lists
  619.  
  620. Building Cons Cells and Lists
  621. =============================
  622.  
  623.    Many functions build lists, as lists reside at the very heart of
  624. Lisp.  `cons' is the fundamental list-building function; however, it is
  625. interesting to note that `list' is used more times in the source code
  626. for Emacs than `cons'.
  627.  
  628.  - Function: cons OBJECT1 OBJECT2
  629.      This function is the fundamental function used to build new list
  630.      structure.  It creates a new cons cell, making OBJECT1 the CAR,
  631.      and OBJECT2 the CDR.  It then returns the new cons cell.  The
  632.      arguments OBJECT1 and OBJECT2 may be any Lisp objects, but most
  633.      often OBJECT2 is a list.
  634.  
  635.           (cons 1 '(2))
  636.                => (1 2)
  637.           (cons 1 '())
  638.                => (1)
  639.           (cons 1 2)
  640.                => (1 . 2)
  641.  
  642.      `cons' is often used to add a single element to the front of a
  643.      list.  This is called "consing the element onto the list".  For
  644.      example:
  645.  
  646.           (setq list (cons newelt list))
  647.  
  648.      Note that there is no conflict between the variable named `list'
  649.      used in this example and the function named `list' described below;
  650.      any symbol can serve both purposes.
  651.  
  652.  - Function: list &rest OBJECTS
  653.      This function creates a list with OBJECTS as its elements.  The
  654.      resulting list is always `nil'-terminated.  If no OBJECTS are
  655.      given, the empty list is returned.
  656.  
  657.           (list 1 2 3 4 5)
  658.                => (1 2 3 4 5)
  659.           (list 1 2 '(3 4 5) 'foo)
  660.                => (1 2 (3 4 5) foo)
  661.           (list)
  662.                => nil
  663.  
  664.  - Function: make-list LENGTH OBJECT
  665.      This function creates a list of length LENGTH, in which all the
  666.      elements have the identical value OBJECT.  Compare `make-list'
  667.      with `make-string' (*note Creating Strings::.).
  668.  
  669.           (make-list 3 'pigs)
  670.                => (pigs pigs pigs)
  671.           (make-list 0 'pigs)
  672.                => nil
  673.  
  674.  - Function: append &rest SEQUENCES
  675.      This function returns a list containing all the elements of
  676.      SEQUENCES.  The SEQUENCES may be lists, vectors, or strings, but
  677.      the last one should be a list.  All arguments except the last one
  678.      are copied, so none of them are altered.
  679.  
  680.      More generally, the final argument to `append' may be any Lisp
  681.      object.  The final argument is not copied or converted; it becomes
  682.      the CDR of the last cons cell in the new list.  If the final
  683.      argument is itself a list, then its elements become in effect
  684.      elements of the result list.  If the final element is not a list,
  685.      the result is a "dotted list" since its final CDR is not `nil' as
  686.      required in a true list.
  687.  
  688.      See `nconc' in *Note Rearrangement::, for a way to join lists with
  689.      no copying.
  690.  
  691.      Here is an example of using `append':
  692.  
  693.           (setq trees '(pine oak))
  694.                => (pine oak)
  695.           (setq more-trees (append '(maple birch) trees))
  696.                => (maple birch pine oak)
  697.           
  698.           trees
  699.                => (pine oak)
  700.           more-trees
  701.                => (maple birch pine oak)
  702.           (eq trees (cdr (cdr more-trees)))
  703.                => t
  704.  
  705.      You can see how `append' works by looking at a box diagram.  The
  706.      variable `trees' is set to the list `(pine oak)' and then the
  707.      variable `more-trees' is set to the list `(maple birch pine oak)'.
  708.      However, the variable `trees' continues to refer to the original
  709.      list:
  710.  
  711.           more-trees                trees
  712.           |                           |
  713.           |     ___ ___      ___ ___   -> ___ ___      ___ ___
  714.            --> |___|___|--> |___|___|--> |___|___|--> |___|___|--> nil
  715.                  |            |            |            |
  716.                  |            |            |            |
  717.                   --> maple    -->birch     --> pine     --> oak
  718.  
  719.      An empty sequence contributes nothing to the value returned by
  720.      `append'.  As a consequence of this, a final `nil' argument forces
  721.      a copy of the previous argument.
  722.  
  723.           trees
  724.                => (pine oak)
  725.           (setq wood (append trees ()))
  726.                => (pine oak)
  727.           wood
  728.                => (pine oak)
  729.           (eq wood trees)
  730.                => nil
  731.  
  732.      This once was the usual way to copy a list, before the function
  733.      `copy-sequence' was invented.  *Note Sequences Arrays Vectors::.
  734.  
  735.      With the help of `apply', we can append all the lists in a list of
  736.      lists:
  737.  
  738.           (apply 'append '((a b c) nil (x y z) nil))
  739.                => (a b c x y z)
  740.  
  741.      If no SEQUENCES are given, `nil' is returned:
  742.  
  743.           (append)
  744.                => nil
  745.  
  746.      Here are some examples where the final argument is not a list:
  747.  
  748.           (append '(x y) 'z)
  749.                => (x y . z)
  750.           (append '(x y) [z])
  751.                => (x y . [z])
  752.  
  753.      The second example shows that when the final argument is a
  754.      sequence but not a list, the sequence's elements do not become
  755.      elements of the resulting list.  Instead, the sequence becomes the
  756.      final CDR, like any other non-list final argument.
  757.  
  758.      The `append' function also allows integers as arguments.  It
  759.      converts them to strings of digits, making up the decimal print
  760.      representation of the integer, and then uses the strings instead
  761.      of the original integers.  *Don't use this feature; we plan to
  762.      eliminate it.  If you already use this feature, change your
  763.      programs now!*  The proper way to convert an integer to a decimal
  764.      number in this way is with `format' (*note Formatting Strings::.)
  765.      or `number-to-string' (*note String Conversion::.).
  766.  
  767.  - Function: reverse LIST
  768.      This function creates a new list whose elements are the elements of
  769.      LIST, but in reverse order.  The original argument LIST is *not*
  770.      altered.
  771.  
  772.           (setq x '(1 2 3 4))
  773.                => (1 2 3 4)
  774.           (reverse x)
  775.                => (4 3 2 1)
  776.           x
  777.                => (1 2 3 4)
  778.  
  779. 
  780. File: lispref.info,  Node: Modifying Lists,  Next: Sets And Lists,  Prev: Building Lists,  Up: Lists
  781.  
  782. Modifying Existing List Structure
  783. =================================
  784.  
  785.    You can modify the CAR and CDR contents of a cons cell with the
  786. primitives `setcar' and `setcdr'.
  787.  
  788.      Common Lisp note: Common Lisp uses functions `rplaca' and `rplacd'
  789.      to alter list structure; they change structure the same way as
  790.      `setcar' and `setcdr', but the Common Lisp functions return the
  791.      cons cell while `setcar' and `setcdr' return the new CAR or CDR.
  792.  
  793. * Menu:
  794.  
  795. * Setcar::          Replacing an element in a list.
  796. * Setcdr::          Replacing part of the list backbone.
  797.                       This can be used to remove or add elements.
  798. * Rearrangement::   Reordering the elements in a list; combining lists.
  799.  
  800. 
  801. File: lispref.info,  Node: Setcar,  Next: Setcdr,  Up: Modifying Lists
  802.  
  803. Altering List Elements with `setcar'
  804. ------------------------------------
  805.  
  806.    Changing the CAR of a cons cell is done with `setcar'.  When used on
  807. a list, `setcar' replaces one element of a list with a different
  808. element.
  809.  
  810.  - Function: setcar CONS OBJECT
  811.      This function stores OBJECT as the new CAR of CONS, replacing its
  812.      previous CAR.  It returns the value OBJECT.  For example:
  813.  
  814.           (setq x '(1 2))
  815.                => (1 2)
  816.           (setcar x 4)
  817.                => 4
  818.           x
  819.                => (4 2)
  820.  
  821.    When a cons cell is part of the shared structure of several lists,
  822. storing a new CAR into the cons changes one element of each of these
  823. lists.  Here is an example:
  824.  
  825.      ;; Create two lists that are partly shared.
  826.      (setq x1 '(a b c))
  827.           => (a b c)
  828.      (setq x2 (cons 'z (cdr x1)))
  829.           => (z b c)
  830.      
  831.      ;; Replace the CAR of a shared link.
  832.      (setcar (cdr x1) 'foo)
  833.           => foo
  834.      x1                           ; Both lists are changed.
  835.           => (a foo c)
  836.      x2
  837.           => (z foo c)
  838.      
  839.      ;; Replace the CAR of a link that is not shared.
  840.      (setcar x1 'baz)
  841.           => baz
  842.      x1                           ; Only one list is changed.
  843.           => (baz foo c)
  844.      x2
  845.           => (z foo c)
  846.  
  847.    Here is a graphical depiction of the shared structure of the two
  848. lists in the variables `x1' and `x2', showing why replacing `b' changes
  849. them both:
  850.  
  851.              ___ ___        ___ ___      ___ ___
  852.      x1---> |___|___|----> |___|___|--> |___|___|--> nil
  853.               |        -->   |            |
  854.               |       |      |            |
  855.                --> a  |       --> b        --> c
  856.                       |
  857.             ___ ___   |
  858.      x2--> |___|___|--
  859.              |
  860.              |
  861.               --> z
  862.  
  863.    Here is an alternative form of box diagram, showing the same
  864. relationship:
  865.  
  866.      x1:
  867.       --------------       --------------       --------------
  868.      | car   | cdr  |     | car   | cdr  |     | car   | cdr  |
  869.      |   a   |   o------->|   b   |   o------->|   c   |  nil |
  870.      |       |      |  -->|       |      |     |       |      |
  871.       --------------  |    --------------       --------------
  872.                       |
  873.      x2:              |
  874.       --------------  |
  875.      | car   | cdr  | |
  876.      |   z   |   o----
  877.      |       |      |
  878.       --------------
  879.  
  880. 
  881. File: lispref.info,  Node: Setcdr,  Next: Rearrangement,  Prev: Setcar,  Up: Modifying Lists
  882.  
  883. Altering the CDR of a List
  884. --------------------------
  885.  
  886.    The lowest-level primitive for modifying a CDR is `setcdr':
  887.  
  888.  - Function: setcdr CONS OBJECT
  889.      This function stores OBJECT as the new CDR of CONS, replacing its
  890.      previous CDR.  It returns the value OBJECT.
  891.  
  892.    Here is an example of replacing the CDR of a list with a different
  893. list.  All but the first element of the list are removed in favor of a
  894. different sequence of elements.  The first element is unchanged,
  895. because it resides in the CAR of the list, and is not reached via the
  896. CDR.
  897.  
  898.      (setq x '(1 2 3))
  899.           => (1 2 3)
  900.      (setcdr x '(4))
  901.           => (4)
  902.      x
  903.           => (1 4)
  904.  
  905.    You can delete elements from the middle of a list by altering the
  906. CDRs of the cons cells in the list.  For example, here we delete the
  907. second element, `b', from the list `(a b c)', by changing the CDR of
  908. the first cell:
  909.  
  910.      (setq x1 '(a b c))
  911.           => (a b c)
  912.      (setcdr x1 (cdr (cdr x1)))
  913.           => (c)
  914.      x1
  915.           => (a c)
  916.  
  917.    Here is the result in box notation:
  918.  
  919.                         --------------------
  920.                        |                    |
  921.       --------------   |   --------------   |    --------------
  922.      | car   | cdr  |  |  | car   | cdr  |   -->| car   | cdr  |
  923.      |   a   |   o-----   |   b   |   o-------->|   c   |  nil |
  924.      |       |      |     |       |      |      |       |      |
  925.       --------------       --------------        --------------
  926.  
  927. The second cons cell, which previously held the element `b', still
  928. exists and its CAR is still `b', but it no longer forms part of this
  929. list.
  930.  
  931.    It is equally easy to insert a new element by changing CDRs:
  932.  
  933.      (setq x1 '(a b c))
  934.           => (a b c)
  935.      (setcdr x1 (cons 'd (cdr x1)))
  936.           => (d b c)
  937.      x1
  938.           => (a d b c)
  939.  
  940.    Here is this result in box notation:
  941.  
  942.      --------------        -------------       -------------
  943.      | car  | cdr   |      | car  | cdr  |     | car  | cdr  |
  944.      |   a  |   o   |   -->|   b  |   o------->|   c  |  nil |
  945.      |      |   |   |  |   |      |      |     |      |      |
  946.       --------- | --   |    -------------       -------------
  947.                 |      |
  948.           -----         --------
  949.          |                      |
  950.          |    ---------------   |
  951.          |   | car   | cdr   |  |
  952.           -->|   d   |   o------
  953.              |       |       |
  954.               ---------------
  955.  
  956. 
  957. File: lispref.info,  Node: Rearrangement,  Prev: Setcdr,  Up: Modifying Lists
  958.  
  959. Functions that Rearrange Lists
  960. ------------------------------
  961.  
  962.    Here are some functions that rearrange lists "destructively" by
  963. modifying the CDRs of their component cons cells.  We call these
  964. functions "destructive" because they chew up the original lists passed
  965. to them as arguments, to produce a new list that is the returned value.
  966.  
  967.    See `delq', in *Note Sets And Lists::, for another function that
  968. modifies cons cells.
  969.  
  970.  - Function: nconc &rest LISTS
  971.      This function returns a list containing all the elements of LISTS.
  972.      Unlike `append' (*note Building Lists::.), the LISTS are *not*
  973.      copied.  Instead, the last CDR of each of the LISTS is changed to
  974.      refer to the following list.  The last of the LISTS is not
  975.      altered.  For example:
  976.  
  977.           (setq x '(1 2 3))
  978.                => (1 2 3)
  979.           (nconc x '(4 5))
  980.                => (1 2 3 4 5)
  981.           x
  982.                => (1 2 3 4 5)
  983.  
  984.      Since the last argument of `nconc' is not itself modified, it is
  985.      reasonable to use a constant list, such as `'(4 5)', as in the
  986.      above example.  For the same reason, the last argument need not be
  987.      a list:
  988.  
  989.           (setq x '(1 2 3))
  990.                => (1 2 3)
  991.           (nconc x 'z)
  992.                => (1 2 3 . z)
  993.           x
  994.                => (1 2 3 . z)
  995.  
  996.      A common pitfall is to use a quoted constant list as a non-last
  997.      argument to `nconc'.  If you do this, your program will change
  998.      each time you run it!  Here is what happens:
  999.  
  1000.           (defun add-foo (x)            ; We want this function to add
  1001.             (nconc '(foo) x))           ;   `foo' to the front of its arg.
  1002.  
  1003.           (symbol-function 'add-foo)
  1004.                => (lambda (x) (nconc (quote (foo)) x))
  1005.  
  1006.           (setq xx (add-foo '(1 2)))    ; It seems to work.
  1007.                => (foo 1 2)
  1008.  
  1009.           (setq xy (add-foo '(3 4)))    ; What happened?
  1010.                => (foo 1 2 3 4)
  1011.  
  1012.           (eq xx xy)
  1013.                => t
  1014.  
  1015.           (symbol-function 'add-foo)
  1016.                => (lambda (x) (nconc (quote (foo 1 2 3 4) x)))
  1017.  
  1018.  - Function: nreverse LIST
  1019.      This function reverses the order of the elements of LIST.  Unlike
  1020.      `reverse', `nreverse' alters its argument by reversing the CDRs in
  1021.      the cons cells forming the list.  The cons cell that used to be
  1022.      the last one in LIST becomes the first cell of the value.
  1023.  
  1024.      For example:
  1025.  
  1026.           (setq x '(1 2 3 4))
  1027.                => (1 2 3 4)
  1028.           x
  1029.                => (1 2 3 4)
  1030.           (nreverse x)
  1031.                => (4 3 2 1)
  1032.           ;; The cell that was first is now last.
  1033.           x
  1034.                => (1)
  1035.  
  1036.      To avoid confusion, we usually store the result of `nreverse' back
  1037.      in the same variable which held the original list:
  1038.  
  1039.           (setq x (nreverse x))
  1040.  
  1041.      Here is the `nreverse' of our favorite example, `(a b c)',
  1042.      presented graphically:
  1043.  
  1044.           Original list head:                       Reversed list:
  1045.            -------------        -------------        ------------
  1046.           | car  | cdr  |      | car  | cdr  |      | car | cdr  |
  1047.           |   a  |  nil |<--   |   b  |   o  |<--   |   c |   o  |
  1048.           |      |      |   |  |      |   |  |   |  |     |   |  |
  1049.            -------------    |   --------- | -    |   -------- | -
  1050.                             |             |      |            |
  1051.                              -------------        ------------
  1052.  
  1053.  - Function: sort LIST PREDICATE
  1054.      This function sorts LIST stably, though destructively, and returns
  1055.      the sorted list.  It compares elements using PREDICATE.  A stable
  1056.      sort is one in which elements with equal sort keys maintain their
  1057.      relative order before and after the sort.  Stability is important
  1058.      when successive sorts are used to order elements according to
  1059.      different criteria.
  1060.  
  1061.      The argument PREDICATE must be a function that accepts two
  1062.      arguments.  It is called with two elements of LIST.  To get an
  1063.      increasing order sort, the PREDICATE should return `t' if the
  1064.      first element is "less than" the second, or `nil' if not.
  1065.  
  1066.      The destructive aspect of `sort' is that it rearranges the cons
  1067.      cells forming LIST by changing CDRs.  A nondestructive sort
  1068.      function would create new cons cells to store the elements in their
  1069.      sorted order.  If you wish to make a sorted copy without
  1070.      destroying the original, copy it first with `copy-sequence' and
  1071.      then sort.
  1072.  
  1073.      Sorting does not change the CARs of the cons cells in LIST; the
  1074.      cons cell that originally contained the element `a' in LIST still
  1075.      has `a' in its CAR after sorting, but it now appears in a
  1076.      different position in the list due to the change of CDRs.  For
  1077.      example:
  1078.  
  1079.           (setq nums '(1 3 2 6 5 4 0))
  1080.                => (1 3 2 6 5 4 0)
  1081.           (sort nums '<)
  1082.                => (0 1 2 3 4 5 6)
  1083.           nums
  1084.                => (1 2 3 4 5 6)
  1085.  
  1086.      Note that the list in `nums' no longer contains 0; this is the same
  1087.      cons cell that it was before, but it is no longer the first one in
  1088.      the list.  Don't assume a variable that formerly held the argument
  1089.      now holds the entire sorted list!  Instead, save the result of
  1090.      `sort' and use that.  Most often we store the result back into the
  1091.      variable that held the original list:
  1092.  
  1093.           (setq nums (sort nums '<))
  1094.  
  1095.      *Note Sorting::, for more functions that perform sorting.  See
  1096.      `documentation' in *Note Accessing Documentation::, for a useful
  1097.      example of `sort'.
  1098.  
  1099. 
  1100. File: lispref.info,  Node: Sets And Lists,  Next: Association Lists,  Prev: Modifying Lists,  Up: Lists
  1101.  
  1102. Using Lists as Sets
  1103. ===================
  1104.  
  1105.    A list can represent an unordered mathematical set--simply consider a
  1106. value an element of a set if it appears in the list, and ignore the
  1107. order of the list.  To form the union of two sets, use `append' (as
  1108. long as you don't mind having duplicate elements).  Other useful
  1109. functions for sets include `memq' and `delq', and their `equal'
  1110. versions, `member' and `delete'.
  1111.  
  1112.      Common Lisp note: Common Lisp has functions `union' (which avoids
  1113.      duplicate elements) and `intersection' for set operations, but
  1114.      XEmacs Lisp does not have them.  You can write them in Lisp if you
  1115.      wish.
  1116.  
  1117.  - Function: memq OBJECT LIST
  1118.      This function tests to see whether OBJECT is a member of LIST.  If
  1119.      it is, `memq' returns a list starting with the first occurrence of
  1120.      OBJECT.  Otherwise, it returns `nil'.  The letter `q' in `memq'
  1121.      says that it uses `eq' to compare OBJECT against the elements of
  1122.      the list.  For example:
  1123.  
  1124.           (memq 'b '(a b c b a))
  1125.                => (b c b a)
  1126.           (memq '(2) '((1) (2)))    ; `(2)' and `(2)' are not `eq'.
  1127.                => nil
  1128.  
  1129.  - Function: delq OBJECT LIST
  1130.      This function destructively removes all elements `eq' to OBJECT
  1131.      from LIST.  The letter `q' in `delq' says that it uses `eq' to
  1132.      compare OBJECT against the elements of the list, like `memq'.
  1133.  
  1134.    When `delq' deletes elements from the front of the list, it does so
  1135. simply by advancing down the list and returning a sublist that starts
  1136. after those elements:
  1137.  
  1138.      (delq 'a '(a b c)) == (cdr '(a b c))
  1139.  
  1140.    When an element to be deleted appears in the middle of the list,
  1141. removing it involves changing the CDRs (*note Setcdr::.).
  1142.  
  1143.      (setq sample-list '(a b c (4)))
  1144.           => (a b c (4))
  1145.      (delq 'a sample-list)
  1146.           => (b c (4))
  1147.      sample-list
  1148.           => (a b c (4))
  1149.      (delq 'c sample-list)
  1150.           => (a b (4))
  1151.      sample-list
  1152.           => (a b (4))
  1153.  
  1154.    Note that `(delq 'c sample-list)' modifies `sample-list' to splice
  1155. out the third element, but `(delq 'a sample-list)' does not splice
  1156. anything--it just returns a shorter list.  Don't assume that a variable
  1157. which formerly held the argument LIST now has fewer elements, or that
  1158. it still holds the original list!  Instead, save the result of `delq'
  1159. and use that.  Most often we store the result back into the variable
  1160. that held the original list:
  1161.  
  1162.      (setq flowers (delq 'rose flowers))
  1163.  
  1164.    In the following example, the `(4)' that `delq' attempts to match
  1165. and the `(4)' in the `sample-list' are not `eq':
  1166.  
  1167.      (delq '(4) sample-list)
  1168.           => (a c (4))
  1169.  
  1170.    The following two functions are like `memq' and `delq' but use
  1171. `equal' rather than `eq' to compare elements.  They are new in Emacs 19.
  1172.  
  1173.  - Function: member OBJECT LIST
  1174.      The function `member' tests to see whether OBJECT is a member of
  1175.      LIST, comparing members with OBJECT using `equal'.  If OBJECT is a
  1176.      member, `member' returns a list starting with its first occurrence
  1177.      in LIST.  Otherwise, it returns `nil'.
  1178.  
  1179.      Compare this with `memq':
  1180.  
  1181.           (member '(2) '((1) (2)))  ; `(2)' and `(2)' are `equal'.
  1182.                => ((2))
  1183.           (memq '(2) '((1) (2)))    ; `(2)' and `(2)' are not `eq'.
  1184.                => nil
  1185.           ;; Two strings with the same contents are `equal'.
  1186.           (member "foo" '("foo" "bar"))
  1187.                => ("foo" "bar")
  1188.  
  1189.  - Function: delete OBJECT LIST
  1190.      This function destructively removes all elements `equal' to OBJECT
  1191.      from LIST.  It is to `delq' as `member' is to `memq': it uses
  1192.      `equal' to compare elements with OBJECT, like `member'; when it
  1193.      finds an element that matches, it removes the element just as
  1194.      `delq' would.  For example:
  1195.  
  1196.           (delete '(2) '((2) (1) (2)))
  1197.                => '((1))
  1198.  
  1199.      Common Lisp note: The functions `member' and `delete' in XEmacs
  1200.      Lisp are derived from Maclisp, not Common Lisp.  The Common Lisp
  1201.      versions do not use `equal' to compare elements.
  1202.  
  1203.    See also the function `add-to-list', in *Note Setting Variables::,
  1204. for another way to add an element to a list stored in a variable.
  1205.  
  1206.